<?php

/**
 * 类名自动加载
 */
class Autoloader
{
    /**
     * 类库自动加载
     * @param string $className 对象类名
     * @return void
     */
    public static function autoload($className)
    {
        $includePath = __DIR__ . DIRECTORY_SEPARATOR . 'src';

        $arr = explode('\\', $className);
        array_shift($arr);
        array_unshift($arr, $includePath);

        $fileName = join(DIRECTORY_SEPARATOR, $arr) . '.php';

        if (file_exists($fileName)) {
            require $fileName;
        } else {
            echo 'Class "' . $className . '" does not exist.';
        }
    }
}

spl_autoload_register('Autoloader::autoload');
